<!-- 找人榜 -->
<template>
	<view class="entrustPeople">
		<uni-nav-bar :fixed="true" statusBar :backgroundColor="'#ffffff'"  :border="false">
			<block slot="left">
				<uni-icons type="back" size="26" @click="returnPage"></uni-icons>
			</block>
			<view class="flex alignCenter nav-center">
				<view class="font16 bold">找人榜</view>
				<view class="input-view flex alignCenter" :class="isSserch?'input-view-show':''">
					<input v-if="isSserch" confirm-type="search" v-model="serchParam.title" class="nav-bar-input font14" type="text" placeholder="输入搜索关键词" @confirm="confirm" />
					<uni-icons class="input-uni-icon" type="search" size="24" color="#999" @click="confirm"/>
				</view>
			</view>
			<block slot="right">
				<uni-icons type="notification" size="24" @click="clickRight"></uni-icons>
				<text class="font10 redDot dot" v-if="noReadNum>0">{{noReadNum>99?'99+':noReadNum}}</text>
			</block>
		</uni-nav-bar>
		
		<view class="contents">
			<view class="list-items flex flexWrap">
				<view class="items" :class="(index%2==1)?'items-right':''" v-for="(item,index) in tableList" :key="index" @click="handleItem(item)">
					<view class="item-info">
						<view class="commission font14 bold">{{item.bounty}}元</view>
						<image :src="item.createUserAvatar" mode="widthFix"></image>
						<view class="userName font12 bold color333">{{item.createUserName}}</view>
						<view class="date font10 colorccc">{{item.createTime}}</view>
						<view class="title font14 bold hiddenTwoline">{{item.title}}</view>
						<view class="schoolName font12 color999 flex alignCenter"> <view>{{item.schoolName}}</view> <view class="majorName">{{item.majorName}}</view> </view>
						<view class="btns flex" :style="item.state?'justify-content: space-around;':''">
							<!-- 本人发布或者状态为已选中，则不展示该按钮 -->
							<view v-if="item.state!=2 && item.createUserId!=userId" class="btn1 font12 color333 flex alignCenter" @click.stop="handleClick(item)">揭榜</view>
							<view v-if="item.state!=2 && item.createUserId!=userId" class="btn2 font12 color333 flex alignCenter" @click.stop="handleShare(item)">接力找人</view>
							<view v-if="item.state==2" class="btn3 font12 color999 flex alignCenter">已揭榜</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 揭榜成功 -->
		<uni-succ v-if="showSuccessTip" @layerOper="layerOper"></uni-succ>
		
		<!-- 找人按钮 -->
		<view class="flex alignCenter findBtn" @click="operClick">
			<view class="">
				<image src="@/static/image/setting/major.png" mode="widthFix"></image>
				<view class="font12">找人</view>
			</view>
		</view>
		
		<uni-nodata v-if="tableList.length<=0"></uni-nodata>
	</view>
</template>

<script>
	import { messAllUnreadNum } from "@/api/mine.js"
	import { relpayOper,foundPersons,askForEduInfo,answerFind} from "@/api/lookFor.js"
	import uniSucc from "@/pages/send/components/uni-succ/uni-succ.vue"
	export default {
		components:{
			uniSucc
		},
		data() {
			return {
				userId: '',
				serchParam: {
					pageNum: 1,
					title: '',
				},
				total: 0,
				noReadNum: 0,
				isSserch: false,
				rightUrl: '/pages/message/message',
				tableList: [],
				showSuccessTip: false,
			}
		},
		onShow(){
			this.userId = uni.getStorageSync('userId');
			this.getQuesNum();
			this.getData();
		},
		methods: {
			// 返回上一页
			returnPage(){
				uni.navigateBack(1);
			},
			// 搜索框
			confirm() {
				if(!this.isSserch){
					this.isSserch = true;
					return
				}
				this.serchParam.pageNum = 1;
				this.getData()
			},
			// 获取问答未读数量
			getQuesNum(){
				if(!uni.getStorageSync('token') || !this.rightIcon) return
				messAllUnreadNum().then((res)=>{
					if(res.code==100000){
						this.noReadNum=Number(res.data.qaMessageUnReadTotal)+Number(res.data.systemMessageUnReadTotal)
					}
				})
			},
			// 查看消息
			clickRight(){
				uni.navigateTo({
					url:this.rightUrl
				})
			},
			
			getData(){
				uni.showLoading({
					title: '数据加载中...'
				})
				let param={
					page: this.serchParam.pageNum,
					title: this.serchParam.title,
					size: 10,
				};
				foundPersons(param).then(res=>{
					if(this.serchParam.pageNum == 1){
						this.tableList = res.data.rows;
						this.total = res.data.total;
					}else{
						this.tableList.push.apply(this.tableList,res.data.rows);
					}
					uni.hideLoading();
				})
			},
			// 揭榜
			handleClick(item){
				//判断信息是否完善
				askForEduInfo().then((res)=>{
					if(res.code==100000){
						// 教育信息状态：-1、未通过，-2，待审核，0：未填写(未通过)；1:已通过（tag没写）；2：已通过:(fileUrls没写); 3已通过（tag没填和fileUrls没填）;4:已通过
						// 职业信息状态：0：未填写；1、未通过，2，待审核，4：已通过
						if(res.data.educationState==-1){
							return uni.showModal({
								title: '提示',
								content: '您的教育信息未通过审核，是否前往修改？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/pages/send/lookFor/postgraduate/enrollment/education?backDelta=3'
										})
									}
								}
							});
						}
						if(res.data.educationState==-2){
							return uni.showModal({
								title: '提示',
								content: '您的教育信息正在审核，通过后才能揭榜哦。',
								success: function (res) {
									if (res.confirm) {
										// uni.navigateTo({
										// 	url:'/pages/send/lookFor/postgraduate/enrollment/education?backDelta=3'
										// })
									}
								}
							});
						}
						if(res.data.educationState==0){
							return uni.showModal({
								title: '提示',
								content: '揭榜前需要完善您的相关信息，是否前往？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/pages/send/lookFor/postgraduate/enrollment/education?backDelta=3'
										})
									}
								}
							});
						}
						
						if(res.data.educationState==1 || res.data.educationState==3){
							return uni.showModal({
								title: '提示',
								content: '揭榜前需要完善您的个人优势信息，是否前往？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/pages/send/lookFor/postgraduate/enrollment/advantage?backDelta=2'
										})
									}
								}
							});
						}
						if(res.data.educationState==2){
							return uni.showModal({
								title: '提示',
								content: '揭榜前需要完善您的个人学历详细简介，是否前往？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/pages/send/lookFor/postgraduate/enrollment/info?backDelta=1'
										})
									}
								}
							});
						}
						
						if(res.data.professionalState==0){
							return uni.showModal({
								title: '提示',
								content: '揭榜前需要完善您的职业信息，是否前往？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/settingPages/pages/job/job'
										})
									}
								}
							});
						}
						if(res.data.professionalState==1){
							return uni.showModal({
								title: '提示',
								content: '您的职业信息未通过审核，是否前往修改？',
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url:'/settingPages/pages/job/job'
										})
									}
								}
							});
						}
						if(res.data.professionalState==2){
							return uni.showModal({
								title: '提示',
								content: '您的职业信息正在审核中，审核通过后才能揭榜哦~',
								success: function (res) {
									if (res.confirm) {
										// uni.navigateTo({
										// 	url:'/pages/send/lookFor/postgraduate/enrollment/education?backDelta=3'
										// })
									}
								}
							});
						}
						
						// 若信息完善，则调用揭榜接口
						// if(res.data.professionalState == 4 && res.data.educationState == 4){
							answerFind({id: item.id}).then((res)=>{
								if(res.code==100000){
									this.showSuccessTip=true
								}
							})
						// }
						
					}
				})	
			},
			layerOper(type){
				if(type=='cancel'){
					this.showSuccessTip=false
				}else{
					uni.navigateTo({
						url:'/pages/mine/queAndAnswer/queAndAnswer'
					})
				}
			},
			// 分享/接力找人
			handleShare(item){
				relpayOper({id: item.id}).then(res=>{
					if(res.code == 100000){
						let query={
							id: item.id,
							inviteType: 6
						}
						uni.navigateTo({
							url:'/pages/school/share/share?query='+JSON.stringify(query)
						})
					}
				})
			},
			// 查看找人详情
			handleItem(item){
				uni.navigateTo({
					url:`/pages/send/lookFor/lookHomepage/lookHomepage?id=${item.id}`
				})
			},
			
			operClick(){
				uni.navigateTo({
					url:'/pages/send/lookFor/publishPeople/publishPeople?type=2'
				})
			},
			
			//底部刷新
			onReachBottom() {
				if(this.tableList.length>=this.total) return;
				this.serchParam.pageNum++;
				this.getData();
			}
			
		},
	}
</script>

<style lang="scss" scoped>
	.entrustPeople{
		background: rgba(235, 238, 239, 0.8);
		min-height: 100vh;
		// uni-nav-bar{
		// 	/* #ifdef MP */
		// 	padding-top: 60rpx;
		// 	/* #endif */
		// }
		// 顶部导航栏
		::v-deep .uni-navbar__header-btns-left,::v-deep .uni-navbar__header-btns-right{
			width: auto!important;
		}
		::v-deep .uni-navbar{
			/* #ifdef MP */
			// padding-top: 60rpx;
			background: #fff;
			/* #endif */
		}
		
		::v-deep .uni-navbar__header{
			/* #ifdef MP */
			position: relative;
			/* #endif */
		}
		::v-deep .uni-navbar__header-btns-right{
			/* #ifdef MP */
			position: absolute;
			right: 180rpx;
			background: #fff;
			top: 14rpx;
			/* #endif */
		}
		.nav-center{
			justify-content: space-between;
			width: 600rpx;
			/* #ifdef MP */
			width: 430rpx;
			/* #endif */
			
			.input-view {
				flex-direction: row;
				// flex: 1;
				background-color: #fff;
				height: 60rpx;
				border-radius: 30rpx;
				// padding: 0 30rpx;
				padding: 0 10rpx 0 30rpx;
				flex-wrap: nowrap;
				margin: 14rpx 0;
				line-height: 60rpx;
				// width: auto;
			}
			.input-view-show{
				background-color: #f8f8f8;
			}
			.input-uni-icon {
				line-height: 60rpx;
			}
			.nav-bar-input {
				height: 60rpx;
				line-height: 60rpx;
				/* #ifdef APP-PLUS-NVUE */
				width: 370rpx;
				/* #endif */
				/* #ifdef MP */
				width: 210rpx;
				/* #endif */
				padding: 0 5px;
				background-color: #f8f8f8;
			}
				
		}
		
		.dot{
			position: absolute;
			width: 30rpx;
			height: 30rpx;
			border-radius: 50%;
			// background: $colorred;
			right:6rpx;
			top: 4rpx;
			text-align: center;
			color: #fff;
			line-height: 30rpx;
		}
		
		.contents{
			margin: 40rpx 30rpx;
			.list-items{
				justify-content: space-between;
			}
			.items{
				position: relative;
				width: 328rpx;
				// height: 366rpx;
				background: #fff;
				text-align: center;
				margin: 40rpx 0;
				border-radius: 10rpx;
				padding-bottom: 40rpx;
				.item-info{
					margin: 0 20rpx;
					image{
						width: 112rpx;
						height: 112rpx;
						border-radius: 50%;
						margin-top: -50rpx;
					}
					.commission{
						position: absolute;
						right: 10px;
						margin-top: 20rpx;
						color: #FF7D5D;	
					}
					.userName{
						line-height: 1em;
						margin: 0px 0 8rpx 0;
					}
					
					
					.title{
						margin-top: 12rpx;
						width: 100%;
						line-height: 32rpx;
						// text-align: center;
						text{
							display: inline-block;
							text-align: left;
							// text-align: left;
						}
					}
					.schoolName,.date{
						line-height: 1em;
					}
					.schoolName{
						text-align: left;
						margin-top: 24rpx;
						.majorName{
							margin-left: 30rpx;
						}
						// justify-content: space-between;
					}
					.btns{
						justify-content: space-between;
						margin-top: 40rpx;
						// padding-bottom: 40rpx;
						.btn1,.btn2,.btn3{
							width: 128rpx;
							height: 48rpx;
							border-radius: 50rpx;
							justify-content: center;
						}
						.btn1{
							background: $colorMain;
						}
						.btn2{
							background: rgba(247,221,94,0.5);
						}
						.btn3{
							background: linear-gradient(to bottom, #EFEFEF, #E6E6E6);
						}
					}
				}
			}
			.items-right{
				// margin-right: 0px!important;
			}
			
			
		}
		
		.findBtn{
			position: fixed;
			right:30rpx;
			bottom: 200rpx;
			width: 112rpx;
			height: 112rpx;
			background:rgba(102, 102, 102, .66);
			border-radius: 50%;
			text-align: center;
			color: #fff;
			&>view{
				margin: 0 auto;
			}
			image{
				width: 48rpx;
				height: 48rpx;
				display: block;
				margin: 0 auto;
			}
		}
	}
</style>